﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Xin478.CSWork.Client
{
    public partial class TipForm : MyForm
    {
        Timer timer;
        int timeout = 15000;
        public TipForm()
        {
            InitializeComponent();
            this.Load+=new EventHandler(TipForm_Load);
            this.textBox1.Cursor = Cursors.Hand;
            this.textBox1.MouseHover += new EventHandler(textBox1_MouseHover);
            this.textBox1.MouseLeave += new EventHandler(textBox1_MouseLeave);
        }

        void textBox1_MouseLeave(object sender, EventArgs e)
        {
            textBox1.ForeColor = Color.Black;
        }

        void textBox1_MouseHover(object sender, EventArgs e)
        {
            textBox1.ForeColor = Color.DodgerBlue;
        }

        public event EventHandler ContentClick;
        public event EventHandler TimeOutClosing;

        void TipForm_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;
            this.Location = new Point( Screen.PrimaryScreen.WorkingArea.Width-Width-10,Screen.PrimaryScreen.WorkingArea.Height-Height);
            if(ContentClick!=null)
                this.textBox1.Click += ContentClick;
            this.textBox1.Click += new EventHandler(textBox1_Click);
            timer = new Timer();
            timer.Interval = timeout;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void textBox1_Click(object sender, EventArgs e)
        {
            timer.Stop();
            timer.Dispose();
            this.Close();
            this.Dispose();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            timer.Dispose();

            if (TimeOutClosing != null) TimeOutClosing(sender, e);
            this.Close();
            this.Dispose();
        }
        public int TimeOut
        {
            set
            {
                this.timeout = value;
            }
            get
            {
                return this.timeout;
            }
        }
        public string Message
        {
            set
            {
                this.textBox1.Text = value;
            }
        }
    }

}
